package com.bbva.recaudos.dao;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.bbva.recaudos.bean.Convenio;
import com.bbva.recaudos.util.Constantes;

public class OracleConvenioDAO implements ConvenioDAO
{
	SqlSessionFactory sqlMapper = null;
	
	{
		try {
			Reader reader = Resources.getResourceAsReader(Constantes.IBATIS_CONFIG_FILE_NAME);
			sqlMapper = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException ex)
		{
			ex.printStackTrace();
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Convenio> obtenerConveniosXEmpresa(int idEmpresa)
	{
		SqlSession session = sqlMapper.openSession();
		List<Convenio> lista = null;
		try
		{
			lista = session.selectList("intercnx.SQL_getConveniosXIdEmpresa", idEmpresa);
			return lista;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return null;
	}	
	

}
